home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / amiga / bmake15.lzh / touch.c < prev    next >
C/C++ Source or Header  |  1991-09-09  |  2KB  |  98 lines

  1. /*    touch.c
  2.  *    (c) Copyright 1991 by Ben Eng, All Rights Reserved
  3.  *
  4.  *    Update the modification time of a file to the present time.
  5.  */
  6.  
  7. #include <exec/memory.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/dos_protos.h>
  11.  
  12. extern struct MsgPort *CreatePort( UBYTE *name, long pri );
  13. extern void DeletePort( struct MsgPort *io );
  14.  
  15. #include <time.h>
  16.  
  17. #include "make.h"
  18.  
  19. /* return the current time */
  20. time_t
  21. nowtime( void )
  22. {
  23.     struct DateStamp t;
  24.     time_t outtime = 0L;
  25.  
  26.     DateStamp( &t );
  27.     outtime = t.ds_Tick/TICKS_PER_SECOND + 60*t.ds_Minute + 86400*t.ds_Days;
  28.     return( outtime );
  29. }
  30.  
  31. static long
  32. dos_packet( struct MsgPort *port, long type, 
  33. long arg1, long arg2, long arg3, long arg4, long arg5, long arg6, long arg7 )
  34. {
  35.     struct StandardPacket *sp;
  36.     struct MsgPort *rp;
  37.     long ret;
  38.  
  39.     if( !( rp = CreatePort( NULL, 0L )))
  40.         return( 1 );
  41.     if( !( sp = AllocMem( sizeof(*sp), MEMF_PUBLIC|MEMF_CLEAR))) {
  42.         DeletePort( rp );
  43.         return( 1 );
  44.     }
  45.     sp->sp_Msg.mn_Node.ln_Name = (char *)&sp->sp_Pkt;
  46.     sp->sp_Pkt.dp_Link = &sp->sp_Msg;
  47.     sp->sp_Pkt.dp_Port = rp;
  48.     sp->sp_Pkt.dp_Type = type;
  49.     sp->sp_Pkt.dp_Arg1 = arg1;
  50.     sp->sp_Pkt.dp_Arg2 = arg2;
  51.     sp->sp_Pkt.dp_Arg3 = arg3;
  52.     sp->sp_Pkt.dp_Arg4 = arg4;
  53.     sp->sp_Pkt.dp_Arg5 = arg5;
  54.     sp->sp_Pkt.dp_Arg6 = arg6;
  55.     sp->sp_Pkt.dp_Arg7 = arg7;
  56.     PutMsg( port, &sp->sp_Msg );
  57.     WaitPort( rp );
  58.     GetMsg( rp );
  59.     ret = sp->sp_Pkt.dp_Res1;
  60.     FreeMem( (void *)sp, sizeof(*sp) );
  61.     DeletePort(rp);
  62.     return( ret );
  63. }
  64.  
  65. /*    update the modification time of a file */
  66. void
  67. touch( const char *filename )
  68. {
  69.     struct MsgPort *task = NULL;
  70.     BPTR lock = (BPTR)0L;
  71.     BPTR plock = (BPTR)0L;
  72.     char *bcplstring = NULL;
  73.     struct DateStamp dateStamp;
  74.  
  75.     if( !( bcplstring = (char *)AllocMem(64L, MEMF_PUBLIC)))
  76.         goto death;
  77.     if( !( task = (struct MsgPort *)DeviceProc( filename )))
  78.         goto death;
  79.     if( !( lock = Lock( filename, SHARED_LOCK )))
  80.         goto death;
  81.     plock = ParentDir( lock );
  82.     UnLock( lock ); lock = NULL;
  83.  
  84.     /* Strip pathnames first */
  85.     strcpy( bcplstring + 1, basename( filename ));
  86.     *bcplstring = (char)strlen(bcplstring + 1);
  87.  
  88.     dos_packet( task, ACTION_SET_DATE, NULL, plock, (long)bcplstring >> 2,
  89.         (long) DateStamp( &dateStamp ), 0L, 0L, 0L);
  90.  
  91. death:
  92.     if( lock )
  93.         UnLock( lock );
  94.     if( plock )
  95.         UnLock( plock );
  96.     FreeMem((void *) bcplstring, 64L );
  97. }
  98.